﻿/*
 * Rappelz: Endless Odyssey - The first free open source Rappelz server emulator
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Rappelz.GameServer.Network.GameClient
{
    /// <summary>
    /// Enum for packets the game client can send to the server
    /// </summary>
    enum ClientInPackets : ushort
    {
        Login = 1,
        TimeSync = 2,
        MoveRequest = 5,
        RegionUpdate = 7,
        Query = 13,
        ChatRequest = 20,
        ReturnLobby = 23,
        RequestLogoutTimer = 25,
        RequestLogoutTimer2 = 26,
        Logout = 27,
        Version = 50,
        Version2 = 51,
        HackShieldMsg = 54,
        GameGuardAuthAnswer = 56,
        CheckIllegalUser = 57,
        XTrapCheck = 59,
        Ping1 = 60,
        AttackRequest = 100,
        CancelAction = 150,
        PutonItem = 200,
        PutoffItem = 201,
        DropItem = 203,
        TakeItem = 204,
        EraseItem = 208,
        Storage = 212,
        PutonCard = 214,
        PutoffCard = 215,
        ItemPositionChange = 218,
        ArrangeItem = 219,
        BuyItem = 251,
        SellItem = 252,
        UseItem = 253,
        Mix = 256,
        DonateItem = 258,
        DonateReward = 259,
        SoulStoneCraft = 260,
        RepairSoulStone = 262,
        OnTrade = 280, // ??
        PutonItemSet = 281,
        BindSkillCard = 284,
        UnBindSkillCard = 285,
        EquipSummon = 303,
        ChangeSummonName = 323,
        GetSummonSetupInfo = 324,
        SetPetName = 354,
        Skill = 400,
        LearnSkill = 402,
        RequestRemoveState = 408,
        JobLevelUp = 410,
        Update = 503,
        Unk1 = 517,
        SetProperty = 508,
        Targeting = 511,
        Resurrection = 513,
        GetRegionInfo = 550,
        DropQuest = 603,
        GetQuestDetails = 604,
        StartBooth = 700,
        StopBooth = 701,
        WatchBooth = 702,
        StopWatchBooth = 704,
        BuyFromBooth = 705,
        SellToBooth = 706,
        GetBoothsName = 707,
        CheckBoothStartable = 711,
        TurnOnPkMode = 800,
        TurnOffPkMode = 801,
        ChangeLocation = 900,
        GetWeatherInfo = 903,
        GameTime = 1100,
        Emotion = 1202,
        AuctionSearch = 1300,
        AuctionSellingList = 1302,
        AuctionBiddedList = 1304,
        AuctionBid = 1306,
        AuctionInstantPurchase = 1308,
        AuctionRegister = 1309,
        AuctionCancel = 1310,
        ItemKeepingList = 1350,
        ItemKeepingTake = 1352,
        CharacterList = 2001,
        CreateCharacter = 2002,
        DeleteCharacter = 2003,
        AccountWithAuth = 2005,
        CheckCharacterName = 2006,
        Dialog = 3001,
        Contact = 3002,
        HuntaholicInstanceList = 4000,
        HuntaholicCreateInstance = 4003,
        HuntaholicJoinInstance = 4004,
        HuntaholicLeaveInstance = 4005,
		HuntaholicLeaveLobby = 4008,
        CompeteRequest = 4500,
        CompeteAnswer = 4502,
        RankingTopRecord = 5000,
        Report = 8000,
        ChangeLocation2 = 9000, // ??
        SecurityNo = 9005,
        Ping2 = 9999,
        OpenItemShop = 10000,
        TakeoutCommercialItem = 10005,
    }


    public class LoginPacketCS : PacketIn
    {
        public String szName;
        public byte race;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public LoginPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            szName = ReadString(19);
            race = (byte)ReadByte();
        }
    }

    public class TimeSyncPacketCS : PacketIn
    {
        public uint time;
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public TimeSyncPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            time = ReadUInt32();
        }
    }

    public class MoveRequestPacketCS : PacketIn
    {
        public uint handle;
        public float x;
        public float y;
        public uint cur_time;
        public bool speed_sync;
        public ushort count;
        public MoveInfo[] infos;

        public class MoveInfo
        {
            public float tx;
            public float ty;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public MoveRequestPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            handle = ReadUInt32();
            x = ReadSingle();
            y = ReadSingle();
            cur_time = ReadUInt32();
            speed_sync = (ReadByte() != 0);
            count = ReadUInt16();
            if(count > 0)
            {
                infos = new MoveInfo[count];
                for(int i = 0; i < (int)count;++i)
                {
                    infos[i] = new MoveInfo();
                    infos[i].tx = ReadSingle();
                    infos[i].ty = ReadSingle();
                }
            }
        }
    }

    public class RegionUpdatePacketCS : PacketIn
    {
        public uint update_time;
        public float x;
        public float y;
        public float z;
        public bool bIsStopMessage;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public RegionUpdatePacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            update_time = ReadUInt32();
            x = ReadSingle();
            y = ReadSingle();
            z = ReadSingle();
            bIsStopMessage = (ReadByte() != 0);
        }
    }

    public class QueryPacketCS : PacketIn
    {
        public uint handle;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public QueryPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            handle = ReadUInt32();
        }
    }

    public class ChatRequestPacketCS : PacketIn
    {
        public String szTarget;
        public byte request_id;
        public byte len;
        public byte type;
        public String szMsg = "";

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public ChatRequestPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            szTarget = ReadString(21);
            request_id = (byte)ReadByte();
            len = (byte)ReadByte();
            type = (byte)ReadByte();
            if(len > 0)
            {
                szMsg = ReadString(len);
            }
        }
    }

    public class ReturnLobbyPacketCS : PacketIn
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public ReturnLobbyPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
        }
    }

    public class LogoutPacketCS : PacketIn
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public LogoutPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
        }
    }

    public class VersionPacketCS : PacketIn
    {
        public String szVersion;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public VersionPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            szVersion = ReadString(20);
        }
    }

/*
        HackShieldMsg = 54,
        GameGuardAuthAnswer = 56,
        CheckIllegalUser = 57,
        XTrapCheck = 59,
        Ping1 = 60,
 */
    public class AttackRequestPacketCS : PacketIn
    {
        public uint handle;
        public uint target;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public AttackRequestPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            handle = ReadUInt32();
            target = ReadUInt32();
        }
    }

    public class CancelActionPacketCS : PacketIn
    {
        public uint handle;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public CancelActionPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            handle = ReadUInt32();
        }
    }

 /* 
        CancelAction = 150,
        PutonItem = 200,
*/
    public class PutonItemPacketCS : PacketIn
    {
        public byte position;
        public uint item_handle;
        public uint target_handle;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public PutonItemPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            position = (byte)ReadByte();
            item_handle = ReadUInt32();
            target_handle = ReadUInt32();
        }
    }

    public class PutoffItemPacketCS : PacketIn
    {
        public byte position;
        public uint target_handle;


        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public PutoffItemPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            position = (byte)ReadByte();
            target_handle = ReadUInt32();
        }
    }

    /*
            DropItem = 203,
     */
    public class TakeItemPacketCS : PacketIn
    {
        public uint taker_handle;
        public uint item_handle;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public TakeItemPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            taker_handle = ReadUInt32();
            item_handle = ReadUInt32();
        }
    }

    public class EraseItemPacketCS : PacketIn
    {
        public int count;
        public uint[] handles;
        public long[] counts;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public EraseItemPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            count = ReadByte();
            handles = new uint[count];
            counts = new long[count];
            for(int i = 0; i < count; ++i)
            {
                handles[i] = ReadUInt32();
                counts[i] = ReadInt64();
            }
            if(handles[0] == count)
            {
                for (int i = 0; i < count; ++i)
                {
                    handles[i] = 0;
                    counts[i] = 0;
                }
            }
        }
    }

    public class StoragePacketCS : PacketIn
    {
        public uint item_handle;
        public byte mode;
        public long count;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public StoragePacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            item_handle = ReadUInt32();
            mode = (byte) ReadByte();
            count = ReadInt64();
        }
    }

    public class PutonCardPacketCS : PacketIn
    {
        public byte pos;
        public uint item_handle;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public PutonCardPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            pos = (byte)ReadByte();
            item_handle = ReadUInt32();
        }
    }

    public class PutoffCardPacketCS : PacketIn
    {
        public byte pos;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public PutoffCardPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            pos = (byte)ReadByte();
        }
    }
    /*

            ItemPositionChange = 218,
     */

    public class ArrangeItemPacketCS : PacketIn
    {
        public bool bIsStorage;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public ArrangeItemPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            bIsStorage = (byte)ReadByte() == 1;
        }
    }

    public class BuyItemPacketCS : PacketIn
    {
        public int item_code;
        public ushort buy_count;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public BuyItemPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            item_code = ReadInt32();
            buy_count = ReadUInt16();
        }
    }

    public class SellItemPacketCS : PacketIn
    {
        public uint handle;
        public ushort sell_count;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public SellItemPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            handle = ReadUInt32();
            sell_count = ReadUInt16();
        }
    }

    public class UseItemPacketCS : PacketIn
    {
        public uint item_handle;
        public uint target_handle;
        public string szParameter;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public UseItemPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            item_handle = ReadUInt32();
            target_handle = ReadUInt32();
            szParameter = ReadString(32);
        }
    }

    public class MixPacketCS : PacketIn
    {
        public class MixInfo
        {
            public uint handle;
            public ushort count;
        }

        public MixInfo main_item = new MixInfo();
        public ushort count;
        public List<MixInfo> vSubItems = new List<MixInfo>();

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public MixPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            main_item.handle = ReadUInt32();
            main_item.count = ReadUInt16();
            count = ReadUInt16();
            for(ushort i = 0; i < count; ++i)
            {
                MixInfo mi = new MixInfo();
                mi.handle = ReadUInt32();
                mi.count = ReadUInt16();
                vSubItems.Add(mi);

            }
        }
    }

     /* 
            DonateItem = 258,
            DonateReward = 259,
      */ 
    public class SoulStoneCraftPacketCS : PacketIn
    {
        public uint craft_item_handle;
        public uint[] soulstone_handle = new uint[4];


        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public SoulStoneCraftPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            craft_item_handle = ReadUInt32();
            for(int i = 0; i < 4; ++i)
            {
                soulstone_handle[i] = ReadUInt32();
            }
        }
    }

    public class RepairSoulStonePacketCS : PacketIn
    {
        public uint[] item_handle = new uint[6];

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public RepairSoulStonePacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            for (int i = 0; i < 6; ++i)
            {
                item_handle[i] = ReadUInt32();
            }
        }
    }

      /* 
            OnTrade = 280, // ??
            PutonItemSet = 281,
            BindSkillCard = 284,
            UnBindSkillCard = 285,
     */
    public class EquipSummonPacketCS : PacketIn
    {
        public bool show_dialog;
        public uint[] card_handle = new uint[6];


        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public EquipSummonPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            show_dialog = ReadByte() != 0;
            for(int i = 0; i < 6; ++i)
            {
                card_handle[i] = ReadUInt32();
            }
        }
    }
     /* 
            EquipSummon = 303,
            ChangeSummonName = 323,
     */

    public class GetSummonSetupInfoPacketCS : PacketIn
    {
        public bool show_dialog;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public GetSummonSetupInfoPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            show_dialog = ReadByte() != 0;
        }
    }

    public class SetPetNamePacketCS : PacketIn
    {
        public uint handle;
        public string name;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public SetPetNamePacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            handle = ReadUInt32();
            name = ReadString(19);
        }
    }

     /* 
            SetPetName = 354,
     */

    public class SkillPacketCS : PacketIn
    {
        public ushort skill_id;
        public uint caster;
        public uint target;
        public float x;
        public float y;
        public float z;
        public byte layer;
        public byte skill_level;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public SkillPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            skill_id = ReadUInt16();
            caster = ReadUInt32();
            target = ReadUInt32();
            x = ReadSingle();
            y = ReadSingle();
            z = ReadSingle();
            layer = (byte) ReadByte();
            skill_level = (byte)ReadByte();
        }
    }


    public class LearnSkillPacketCS : PacketIn
    {
        public uint target;
        public int skill_id;
        public short skill_level;


        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public LearnSkillPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            target = ReadUInt32();
            skill_id = ReadInt32();
            skill_level = ReadInt16();
        }
    }

    /*
            RequestRemoveState = 408,
     */

    public class JobLevelUpPacketCS : PacketIn
    {
        public uint target;


        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public JobLevelUpPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            target = ReadUInt32();
        }
    }

    public class UpdatePacketCS : PacketIn
    {
        public uint handle;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public UpdatePacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            handle = ReadUInt32();
        }
    }

    public class SetPropertyPacketCS : PacketIn
    {
        public string name;
        public string value;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public SetPropertyPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            name = ReadString(16);
            value = ReadString((int)this.Length - 23);
        }
    }

    public class TargetingPacketCS : PacketIn
    {
        public uint target;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public TargetingPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            target = ReadUInt32();
        }
    }

    public class ResurrectionPacketCS : PacketIn
    {
        public uint handle;

// Enum           :   <unnamed-tag>, Type: int
// Data           :     constant 0x0, Constant, Type: int, RESURRECT_TYPE_NORMAL
// Data           :     constant 0x1, Constant, Type: int, RESURRECT_TYPE_BY_STATE
// Data           :     constant 0x2, Constant, Type: int, RESURRECT_TYPE_BY_POTION
// Data           :     constant 0x3, Constant, Type: int, RESURRECT_TYPE_BY_COMPETE
        public byte type;


        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public ResurrectionPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            handle = ReadUInt32();
            type = (byte)ReadByte();
        }
    }
 
    public class GetRegionInfoPacketCS : PacketIn
    {
        public float x;
        public float y;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public GetRegionInfoPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            x = ReadSingle();
            y = ReadSingle();
        }
    }

    public class DropQuestPacketCS : PacketIn
    {
        public int quest_id;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public DropQuestPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            quest_id = ReadInt32();
        }
    }

    public class GetQuestDetailsPacketCS : PacketIn
    {
        public int quest_id;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public GetQuestDetailsPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            quest_id = ReadInt32();
        }
    }
 
 /* 
        StartBooth = 700,
        StopBooth = 701,
        WatchBooth = 702,
        StopWatchBooth = 704,
        BuyFromBooth = 705,
        SellToBooth = 706,
        GetBoothsName = 707,
        CheckBoothStartable = 711,
        TurnOnPkMode = 800,
        TurnOffPkMode = 801,
*/
    public class ChangeLocationPacketCS : PacketIn
    {
        public float x;
        public float y;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public ChangeLocationPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            x = ReadSingle();
            y = ReadSingle();
        }
    }
 
/*
  
        GetWeatherInfo = 903,
*/
    public class GameTimePacketCS : PacketIn
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public GameTimePacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
        }
    }

    public class EmotionPacketCS : PacketIn
    {
        public int emotion;
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public EmotionPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            emotion = ReadInt32();
        }
    }
 
 
/*
        AuctionSearch = 1300,
        AuctionSellingList = 1302,
        AuctionBiddedList = 1304,
        AuctionBid = 1306,
        AuctionInstantPurchase = 1308,
        AuctionRegister = 1309,
        AuctionCancel = 1310,
        ItemKeepingList = 1350,
        ItemKeepingTake = 1352,
 */
    public class CharacterListPacketCS : PacketIn
    {
        public String szAccount;
        
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public CharacterListPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            szAccount = ReadString(61);
        }
    }

    public class CreateCharacterPacketCS : PacketIn
    {
        public LobbyCharacterInfo info = new LobbyCharacterInfo();

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public CreateCharacterPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            info.sex = ReadInt32();
            info.race = ReadInt32();

            for(int i = 0; i < 5; ++i)
            {
                info.model_id[i] = ReadInt32();
            }


            if (this.m_psize >= 468)
            {
                info.hair_color_index = ReadInt32();
                info.hair_color_rgb = ReadInt32();
                info.hide_equip_flag = ReadInt32();
//                    o.WriteUInt32(1); // hair dye
//                  o.WriteUInt32(10); // filler for 7.2
//                o.WriteUInt32(22); // filler for 7.2
            }
            if (this.m_psize >= 456) // v6.2
            {
                info.texture_id = ReadInt32();
            }
//                    o.WriteUInt32(2); // face

            for (int i = 0; i < 24; ++i)
            {
                info.wear_info[i] = ReadInt32();
            }
            // end of model_info

            info.level = ReadInt32();
            info.job = ReadInt32();
            info.job_level = ReadInt32();
            info.exp = ReadInt32();
            info.hp = ReadInt32();
            info.mp = ReadInt32();
            info.permission = ReadInt32();
            info.is_banned = (ReadByte() == 1);
            info.name = ReadString(19);
            info.skin_color = ReadUInt32();
            info.szCreateTime = ReadString(30);
            info.szDeleteTime = ReadString(30);

            for(int i = 0; i < 24; ++i)
            {
                info.wear_item_enhance_info[i] = ReadInt32();
            }
            for(int i = 0; i < 24; ++i)
            {
                info.wear_item_level_info[i] = ReadInt32();
            }
            for(int i = 0; i < 24; ++i)
            {
                info.wear_item_elemental_type[i] = (byte)ReadByte();
            }

        }
    }

    public class DeleteCharacterPacketCS : PacketIn
    {
        public string szName;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public DeleteCharacterPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            szName = ReadString(19);
        }
    }

    public class AccountWithAuthPacketCS : PacketIn
    {
        public String szAccount;
        public long one_time_key;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public AccountWithAuthPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            szAccount = ReadString(61);
            one_time_key = ReadInt64();
        }
    }

    public class CheckCharacterNamePacketCS : PacketIn
    {
        public String szName;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public CheckCharacterNamePacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            szName = ReadString(19);
        }
    }

    public class DialogPacketCS : PacketIn
    {
        public ushort tsize;
        public string trigger;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public DialogPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            tsize = ReadUInt16();
            trigger = ReadString(tsize);
        }
    }

    public class ContactPacketCS : PacketIn
    {
        public uint handle;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public ContactPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            handle = ReadUInt32();
        }
    }
     /* 
            HuntaholicInstanceList = 4000,
            HuntaholicCreateInstance = 4003,
            HuntaholicJoinInstance = 4004,
            HuntaholicLeaveInstance = 4005,
            HuntaholicLeaveLobby = 4008,
            CompeteRequest = 4500,
            CompeteAnswer = 4502,
            RankingTopRecord = 5000,
*/
    public class ReportPacketCS : PacketIn
    {
        public ushort report_len;
        public String report;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public ReportPacketCS(byte[] buf, int start, int size)
            : base(buf, start, size)
        {
            report_len = ReadUInt16();
            report = ReadString(report_len);
        }
    }

    /*      
                ChangeLocation = 9000,
                SecurityNo = 9005,
                Ping2 = 9999,
                OpenItemShop = 10000,
                TakeoutCommercialItem = 10005,
        */

    public class ModelInfo
    {
        public int sex;                                 // 0x0
        public int race;                                // 0x4;
        public int[] model_id = new int[5];             // 0x8
        public int hair_color_index;                    // 0x1C
        public int hair_color_rgb;                      // 0x20
        public int hide_equip_flag;                     // 0x24
        public int texture_id;                          // 0x28
        public int[] wear_info = new int[24];           // 0x2C
    }

    public class LobbyCharacterInfo : ModelInfo
    {
        public int level;                                           // 0x8C
        public int job;                                             // 0x90
        public int job_level;                                       // 0x84
        public int exp;                                             // 0x98
        public int hp;                                              // 0x9C
        public int mp;                                              // 0xA0
        public int permission;                                      // 0xA4
        public bool is_banned;                                      // 0xA8
        public string name;                                         // 0xA9 [19]
        public uint skin_color;                                     // 0xBC
        public string szCreateTime;                                 // 0xC0 [30]
        public string szDeleteTime;                                 // 0xDE [30]
        public int[] wear_item_enhance_info = new int[24];          // 0xFC
        public int[] wear_item_level_info = new int[24];            // 0x15C
        public byte[] wear_item_elemental_type = new byte[24];      // 0x1BC
        public int[] wear_appearance_code = new int[24];            // 0x1D4
    }


    class ClientPackets
    {
    }
}
